﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using DotNetEngine.Input;
using DotNetEngine.Utils;
#endregion

namespace DotNetEngine.GUI
{
    public class MenuControl
    {
        #region Propierties
        public List<MenuItem> options;
        public int SelectedItem;
        int layer;
        Vector2 position; 
        #endregion

        #region Initialize methods
        public MenuControl(Vector2 pos, int layer)
        {
            options = new List<MenuItem>();
            SelectedItem = 0;
            this.layer = layer;
            position = pos;
        } 

        #endregion

        #region Public methods
        public void AddMenuItem(String text, MenuItem.actionhandler action)
        {
            options.Add(new MenuItem(text, position, Color.Black, layer, action));
            position.Y = position.Y + 22;
        }
        public void AddMenuItem(MenuItem m)
        {
            m.Option.Position = position;
            options.Add(m);
            position.Y = position.Y + 22;
        }
        public void Update()
        {
            if (InputManager.KeyboardKeyJustPressed(Keys.Down) && (SelectedItem < options.Count - 1))
            {
                SelectedItem++;
            }
            if (InputManager.KeyboardKeyJustPressed(Keys.Up) && (SelectedItem > 0))
            {
                SelectedItem--;
            }
            if (InputManager.KeyboardKeyJustPressed(Keys.Enter))
            {
                options[SelectedItem].action();
            }
        }
        public void Draw()
        {
            for (int i = 0; i < options.Count; i++)
            {
                options[i].Draw(i == SelectedItem);
            }
        } 
        #endregion
    }
}
